package edu.upc.fib.lamsandroid.client.fragment.lesson;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import com.google.gson.Gson;
import edu.upc.fib.lamsandroid.client.Util;
import edu.upc.fib.lamsandroid.server.api.model.ToolContent;
import edu.upc.fib.lamsandroid.server.api.model.ToolContentDataNoticeBoard;

public class NoticeBoardLessonFragment extends Fragment {

    private final ToolContent toolContent;

    public NoticeBoardLessonFragment(ToolContent toolContent) {
        this.toolContent = toolContent;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Context c = getActivity().getApplicationContext();

        LinearLayout layout = new LinearLayout(c);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.MATCH_PARENT, 0);

        layout.setLayoutParams(params);

        final ToolContentDataNoticeBoard nbContent
                = new Gson().fromJson(toolContent.getData().getJson(), ToolContentDataNoticeBoard.class);

        Util.addWebView(getActivity(), layout, nbContent.getData());

        ScrollView scrollView = new ScrollView(getActivity());
        scrollView.addView(layout);
        return scrollView;
    }
}
